﻿@functions {
    // To support the layout classifaction below. Implementing as a razor function because we can, could otherwise be a Func<string[], string, string> in the code block following.
    string CalcuClassify(string[] zoneNames, string classNamePrefix) {
        var zoneCounter = 0;
        var zoneNumsFilled = string.Join("", zoneNames.Select(zoneName => { ++zoneCounter; return Model[zoneName] != null ? zoneCounter.ToString() : ""; }).ToArray());
        return HasText(zoneNumsFilled) ? classNamePrefix + zoneNumsFilled : "";
    }
}
@{
    /* Global includes for the theme
    ***************************************************************/

    SetMeta("X-UA-Compatible", "IE=edge,chrome=1");
    SetMeta("viewport", "width=device-width, initial-scale=1, maximum-scale=1");
    //Style.Include("bootstrap.css"); // standard style sheet
    Style.Include("bootstrap.min.css"); // minified style sheet
    //Style.Include("bootstrap-responsive.css"); // standard responsive style sheet
    Style.Include("bootstrap-responsive.min.css"); // minified responsive style sheet
    //Style.Include("less/bootstrapless.less"); // LESS implementation *Requires DOTLESS module
    Style.Include("site.css"); // theme specific standard style sheet
    Script.Require("jQuery").AtHead();
    //Script.Include("bootstrap.js"); // standard javascript file
    Script.Include("bootstrap.min.js"); // minified javascript file

    /* Some useful shortcuts or settings
    ***************************************************************/

    Func<dynamic, dynamic> Zone = x => Display(x); // Zone as an alias for Display to help make it obvious when we're displaying zones

    /* Layout classification based on filled zones
    ***************************************************************/

    //Add classes to the wrapper div to toggle aside widget zones on and off
    var asideClass = CalcuClassify(new[] { "AsideFirst", "AsideSecond" }, "aside-"); // for aside-1, aside-2 or aside-12 if any of the aside zones are filled
    if (HasText(asideClass)) {
        Model.Classes.Add(asideClass);
    }

    //Add classes to the wrapper div to toggle tripel widget zones on and off
    var tripelClass = CalcuClassify(new[] { "TripelFirst", "TripelSecond", "TripelThird" }, "tripel-"); // for tripel-1, triple-2, etc. if any of the tripel zones are filled
    if (HasText(tripelClass)) {
        Model.Classes.Add(tripelClass);
    }

    //Add classes to the wrapper div to toggle quad widget zones on and off
    var footerQuadClass = CalcuClassify(new[] { "FooterQuadFirst", "FooterQuadSecond", "FooterQuadThird", "FooterQuadFourth" }, "split-"); // for quad-1, quad-2, etc. if any of the quad zones are filled
    if (HasText(footerQuadClass)) {
        Model.Classes.Add(footerQuadClass);
    }

    /* Inserting some ad hoc shapes
    ***************************************************************/

    WorkContext.Layout.Navigation.Add(New.Branding(), "0"); // Site name and link to the home page
    WorkContext.Layout.Footer.Add(New.BadgeOfHonor(), "5"); // Powered by Orchard
    WorkContext.Layout.Navigation.Add(New.User(), "5"); // Login and dashboard links
    WorkContext.Layout.Navigation.Add(New.SearchNav(), "10"); // Search box (requires Search module)

    /* Last bit of code to prep the layout wrapper
    ***************************************************************/

    Model.Id = "layout-wrapper";
    var tag = Tag(Model, "div"); // using Tag so the layout div gets the classes, id and other attributes added to the Model
}
@tag.StartElement
@if (Model.Navigation != null) {
    <!--start: Navigation -->
    <div id="layout-navigation" class="navbar navbar-inverse navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container">
                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>
                <div class="nav-collapse collapse">
                    @Zone(Model.Navigation)
                </div>
            </div>
        </div>
    </div>
    <!--end: Navigation -->
}
<!--start: Container -->
<div class="container" style="padding-top: 60px;">
    @if (Model.Header != null) {
        <!--start: Row -->
        <div class="row">
            <header id="layout-header">
                @Zone(Model.Header)
            </header>
        </div>
        <!--end: Row -->
    }
    @if (Model.Featured != null) {
        <!-- start: Hero Unit - Main hero unit for a primary marketing message or call to action -->
        <div id="layout-featured" class="hero-unit">
            @Zone(Model.Featured)
        </div>
        <!-- end: Hero Unit -->
    }
    @if (Model.BeforeMain != null) {
        <!--start: Row -->
        <div class="row">
            <div id="layout-before-main">
                @Zone(Model.BeforeMain)
            </div>
        </div>
        <!--end: Row -->
        <hr />
    }
    <!--start: Row -->
    <div class="row" style="@(HasText(asideClass) ? "" : "margin-left: 0;" )">
        @if (Model.AsideFirst != null) {
            <div class="span3">
                <div class="well">
                    @Zone(Model.AsideFirst)
                </div>
            </div>
        }
        <div class="@(HasText(asideClass) ? asideClass == "aside-1" || asideClass == "aside-2" ? "span9" : asideClass == "aside-12" ? "span6" : "span12" : "")">
            @if (Model.Messages != null) {
                <div>
                    @Zone(Model.Messages)
                </div>
            }
            @if (Model.BeforeContent != null) {
                <div>
                    @Zone(Model.BeforeContent)
                </div>
            }
            @if (Model.Content != null) {
                <div>
                    @Zone(Model.Content)
                </div>
            }
            @if (Model.AfterContent != null) {
                <div>
                    @Zone(Model.AfterContent)
                </div>
            }
        </div>
        @if (Model.AsideSecond != null) {
            <div class="span3">
                <div class="well">
                    @Zone(Model.AsideSecond)
                </div>
            </div>
        }
    </div>
    <!--end: Row -->
    <hr />
    @if (Model.AfterMain != null) {
        <!-- start: Row -->
        <div class="row">
            @Zone(Model.AfterMain)
        </div>
        <!-- end: Row -->
        <hr />
    }
    @if (Model.TripelFirst != null || Model.TripelSecond != null || Model.TripelThird != null) {
        <!-- start: Row -->
        <div class="row">
            <!-- start: Tripel Container -->
            <div id="layout-tripel-container">
                @if (Model.TripelFirst != null) {
                    <!-- start: Tripel -->
                    <div class="@(HasText(tripelClass) ? tripelClass == "tripel-12" || tripelClass == "tripel-23" || tripelClass == "tripel-13" ? "span6" : tripelClass == "tripel-123" ? "span4" : "span12" : "")">
                        @Zone(Model.TripelFirst)
                    </div>
                    <!-- end: Tripel -->
                }
                @if (Model.TripelSecond != null) {
                    <!-- start: Tripel -->
                    <div class="@(HasText(tripelClass) ? tripelClass == "tripel-12" || tripelClass == "tripel-23" || tripelClass == "tripel-13" ? "span6" : tripelClass == "tripel-123" ? "span4" : "span12" : "")">
                        @Zone(Model.TripelSecond)
                    </div>
                    <!-- end: Tripel -->
                }
                @if (Model.TripelThird != null) {
                    <!-- start: Tripel -->
                    <div class="@(HasText(tripelClass) ? tripelClass == "tripel-12" || tripelClass == "tripel-23" || tripelClass == "tripel-13" ? "span6" : tripelClass == "tripel-123" ? "span4" : "span12" : "")">
                        @Zone(Model.TripelThird)
                    </div>
                    <!-- end: Tripel -->
                }
            </div>
            <!-- end: Tripel Container -->
        </div>
        <!-- end: Row -->
        <hr />
    }
</div>
<div id="push"></div>
<!--end: Container-->
@tag.EndElement
<!-- start: Footer -->
<footer id="footer">
    @if (Model.FooterQuadFirst != null || Model.FooterQuadSecond != null || Model.FooterQuadThird != null || Model.FooterQuadFourth != null) {
        <!-- start: Container -->
        <div class="container">
            <!-- start: Row -->
            <div class="row">
                @if (Model.FooterQuadFirst != null) {
                    <div class="@(HasText(footerQuadClass) ? footerQuadClass == "split-1" || footerQuadClass == "split-2" || footerQuadClass == "split-3" || footerQuadClass == "split-4" ? "span12" : footerQuadClass == "split-12" || footerQuadClass == "split-13" || footerQuadClass == "split-14" || footerQuadClass == "split-23" || footerQuadClass == "split-24" || footerQuadClass == "split-34" ? "span6" : footerQuadClass == "split-123" || footerQuadClass == "split-124" || footerQuadClass == "split-134" || footerQuadClass == "split-234" ? "span4" : "span3" : "")">
                        @Zone(Model.FooterQuadFirst)
                    </div>
                }
                @if (Model.FooterQuadSecond != null) {
                    <div class="@(HasText(footerQuadClass) ? footerQuadClass == "split-1" || footerQuadClass == "split-2" || footerQuadClass == "split-3" || footerQuadClass == "split-4" ? "span12" : footerQuadClass == "split-12" || footerQuadClass == "split-13" || footerQuadClass == "split-14" || footerQuadClass == "split-23" || footerQuadClass == "split-24" || footerQuadClass == "split-34" ? "span6" : footerQuadClass == "split-123" || footerQuadClass == "split-124" || footerQuadClass == "split-134" || footerQuadClass == "split-234" ? "span4" : "span3" : "")">
                        @Zone(Model.FooterQuadSecond)
                    </div>
                }
                @if (Model.FooterQuadThird != null) {
                    <div class="@(HasText(footerQuadClass) ? footerQuadClass == "split-1" || footerQuadClass == "split-2" || footerQuadClass == "split-3" || footerQuadClass == "split-4" ? "span12" : footerQuadClass == "split-12" || footerQuadClass == "split-13" || footerQuadClass == "split-14" || footerQuadClass == "split-23" || footerQuadClass == "split-24" || footerQuadClass == "split-34" ? "span6" : footerQuadClass == "split-123" || footerQuadClass == "split-124" || footerQuadClass == "split-134" || footerQuadClass == "split-234" ? "span4" : "span3" : "")">
                        @Zone(Model.FooterQuadThird)
                    </div>
                }
                @if (Model.FooterQuadFourth != null) {
                    <div class="@(HasText(footerQuadClass) ? footerQuadClass == "split-1" || footerQuadClass == "split-2" || footerQuadClass == "split-3" || footerQuadClass == "split-4" ? "span12" : footerQuadClass == "split-12" || footerQuadClass == "split-13" || footerQuadClass == "split-14" || footerQuadClass == "split-23" || footerQuadClass == "split-24" || footerQuadClass == "split-34" ? "span6" : footerQuadClass == "split-123" || footerQuadClass == "split-124" || footerQuadClass == "split-134" || footerQuadClass == "split-234" ? "span4" : "span3" : "")">
                        @Zone(Model.FooterQuadFourth)
                    </div>
                }
            </div>
            <!-- end: Row -->
            <hr />
        </div>
        <!-- end: Container -->
    }
    @if (Model.Footer != null) {
        <!-- start: Container -->
        <div class="container">
            <!-- start: Row -->
            <div class="row">
                @Zone(Model.Footer)
            </div>
            <!-- end: Row -->
        </div>
        <!-- end: Container -->
    }
</footer>
<!-- end: Footer -->
